package com.waterworld.watch.common.net;

import android.database.Observable;
import android.support.v7.widget.RecyclerView;

import com.alibaba.sdk.android.push.CloudPushService;
import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory;
import com.squareup.okhttp.MultipartBuilder;
import com.waterworld.watch.common.application.MyApplication;
import com.waterworld.watch.common.bean.*;
import com.waterworld.watch.home.bean.RoleBean;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.http.Url;
import rx.Observer;
import rx.Subscriber;


/**
 * Created by nhuan
 * Time:2018/12/14.
 */

public class NetManager implements INetManager {

    private static NetManager mInstance;

    public static NetManager getInstance() {
        if (mInstance == null) {
            synchronized (NetManager.class) {
                if (mInstance == null) {
                    mInstance = new NetManager();
                }
            }
        }
        return mInstance;
    }

    /**
     * 获取短信验证码
     *
     * @param phone      手机号码
     * @param type       验证类型(0-登录，1-注册，2-修改密码，3-修改手机号-需要认证)
     * @param subscriber
     */
    @Override
    public void getAuthCode(String phone, String type, Subscriber<BaseResultBean<String>> subscriber) {
        RetrofitClient.getInstance().getApiService().getAuthCode(UrlContants.GET_AUTH_CODE, phone, type)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 注册
     *
     * @param phone      手机号码
     * @param pwd        密码
     * @param authCode   验证码
     * @param subscriber
     */
    @Override
    public void register(String phone, String pwd, String authCode, Subscriber<BaseResultBean> subscriber) {
        Map<String, String> map = new HashMap<>();
        map.put("phone", phone);
        map.put("pwd", pwd);
        map.put("authCode", authCode);
        RetrofitClient.getInstance().getApiService().register(UrlContants.REGISTER, map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }


    /**
     * 登录
     *
     * @param phone      手机号
     * @param type       登录类型（0-账号密码登录，1-验证码登录）
     * @param pwd        密码
     * @param subscriber
     */
    @Override
    public void login(String phone, String type, String pwd,Subscriber<BaseResultBean<String>> subscriber) {
        Map<String, String> map = new HashMap<>();
        map.put("phone", phone);
        map.put("type", type);
        if (type.equals("0")) {     //密码登录
            map.put("pwd", pwd);
        } else if (type.equals("1")) {     //验证码登录
            map.put("authCode", pwd);
        }
        //登录机型 android 1,iphone 2
        map.put("loginDeviceType","1");
        CloudPushService pushService = PushServiceFactory.getCloudPushService();
        String deviceId = pushService.getDeviceId();
        map.put("loginDevicePushToken", deviceId+"_"+phone);
        RetrofitClient.getInstance().getApiService().login(UrlContants.LOGIN, map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe((Observer) subscriber);
    }

    /**
     * 忘记密码
     *
     * @param phone      手机号
     * @param pwd        密码
     * @param authCode   验证码
     * @param subscriber
     */
    @Override
    public void forgetPwd(String phone, String pwd, String authCode, Subscriber<BaseResultBean> subscriber) {
        Map<String, String> map = new HashMap<>();
        map.put("phone", phone);
        map.put("pwd", pwd);
        map.put("authCode", authCode);
        RetrofitClient.getInstance().getApiService().forgetPwd(UrlContants.FORGET_PASSWORD, map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 修改密码
     *
     * @param newPwd     新密码
     * @param oldPwd     旧密码
     * @param subscriber
     */
    @Override
    public void modifyPwd(String newPwd, String oldPwd, Subscriber<BaseResultBean> subscriber) {
        Map<String, String> map = new HashMap<>();
        map.put("newPwd", newPwd);
        map.put("oldPwd", oldPwd);
        RetrofitClient.getInstance().getApiService().modifyPwd(UrlContants.MODIFY_PASSWORD, map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 修改账号
     *
     * @param newPhone   新手机号码
     * @param authCode   旧手机号码
     * @param pwd        原密码
     * @param subscriber
     */
    @Override
    public void modifyPhone(String newPhone, String authCode, String pwd, Subscriber<BaseResultBean> subscriber) {
        Map<String, String> map = new HashMap<>();
        map.put("newPhone", newPhone);
        map.put("authCode", authCode);
        map.put("pwd", pwd);
        RetrofitClient.getInstance().getApiService().modifyPhone(UrlContants.MODIFY_PHONE, map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }


    /**
     * 修改用户信息
     *
     * @param head             头像名，无修改可为null，系统图像名前缀加"sys_"用于标识
     * @param name             用户名
     * @param relationWithBaby 与宝贝关系
     * @param subscriber
     */
    @Override
    public void modifyUserInfo(String head, String name, String relationWithBaby, Subscriber<BaseResultBean> subscriber) {
        Map<String, String> map = new HashMap<>();
        map.put("head", head);
        map.put("name", name);
        map.put("relationWithBaby", relationWithBaby);
        RetrofitClient.getInstance().getApiService().modifyUserInfo(UrlContants.MODIFY_USERINFO, map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 获取用户信息
     *
     * @param subscriber
     */
    @Override
    public void getCurrentUser(Subscriber<BaseResultBean<UserInfoBean>> subscriber) {
        RetrofitClient.getInstance().getApiService().getCurrentUser(UrlContants.GET_CURRENT_USER)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 退出系统
     *
     * @param subscriber
     */
    @Override
    public void logout(Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().logout(UrlContants.LOGOUT)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 检查imei
     * @param imei
     * @param subscriber
     */
    @Override
    public void checkImei(String imei, Subscriber<BaseResultBean> subscriber) {
        Map<String,Object> map = new HashMap<>();
        map.put("imei",imei);
        RetrofitClient.getInstance().getApiService().checkImei(UrlContants.CHECK_IMEI,map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 绑定手表
     */
    @Override
    public void bindWatch(String imei , String relationWithBaby,String head,String name,Integer sex,String birthday,String grade,String classes,String height,String weight, String phone,Subscriber<BaseResultBean<RoleBean>> subscriber) {
        Map<String, Object> map = new HashMap<>();
        map.put("imei", imei);
        map.put("relationWithBaby",relationWithBaby);
        if (head != null && name != null && sex != null && birthday != null && grade != null && classes != null && height != null && weight != null && phone != null) {
            map.put("head",head);
            map.put("name",name);
            map.put("sex",sex);
            map.put("birthday",birthday);
            map.put("grade",grade);
            map.put("classes",classes);
            map.put("height",height);
            map.put("weight",weight);
            map.put("phone",phone);
        }
        RetrofitClient.getInstance().getApiService().bindWatch(UrlContants.BIND_WATCH, map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }


    /**
     * 保存或更新手表用户
     * @param head
     * @param name
     * @param sex
     * @param birthday
     * @param grade
     * @param classes
     * @param height
     * @param weight
     * @param phone
     * @param subscriber
     */
    @Override
    public void saveWatchUserInfo(String head,String name,Integer sex,String birthday,String grade,String classes,String height,String weight, String phone, Subscriber<BaseResultBean> subscriber) {
        Map<String, Object> map = new HashMap<>();
        map.put("head", head);
        map.put("name", name);
        map.put("sex", sex);
        map.put("birthday", birthday);
        map.put("grade", grade);
        map.put("classes", classes);
        map.put("height", height);
        map.put("weight", weight);
        map.put("phone", phone);
        RetrofitClient.getInstance().getApiService().saveWatchUserInfo(UrlContants.SAVE_WATCH_USERINFO, map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 切换手表
     *
     * @param watchId    手表ID
     * @param subscriber
     */
    @Override
    public void switchWatch(Integer watchId, Subscriber<BaseResultBean> subscriber) {
        Map<String, Integer> map = new HashMap<>();
        if (watchId != null) {
            map.put("watchId", watchId);
        }
        RetrofitClient.getInstance().getApiService().switchWatch(UrlContants.SWITCH_WATCH, map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 获取当前手表用户信息
     *
     * @param subscriber
     */
    @Override
    public void getCurrentWatchUserInfo(Subscriber<BaseResultBean<WatchUserInfoBean>> subscriber) {
        RetrofitClient.getInstance().getApiService().getCurrentWatchUserInfo(UrlContants.GET_CURRENT_WATCH_USERIFO)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 获取用户绑定手表列表
     *
     * @param subscriber
     */
    @Override
    public void listBindWatch(Subscriber<BaseResultBean<BindWatchBean[]>> subscriber) {
        RetrofitClient.getInstance().getApiService().listBindWatch(UrlContants.LIST_BIND_WATCH)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 获取绑定该手表的用户列表
     *
     * @param subscriber
     */
    @Override
    public void listBindWatchUser(Subscriber<BaseResultBean<BindWatchUserBean[]>> subscriber) {
        RetrofitClient.getInstance().getApiService().listBindWatchUser(UrlContants.LIST_BIND_WATCHUSER)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 移交管理权限
     *
     * @param authorizeeUserId 被授权用户标识
     * @param subscriber
     */
    @Override
    public void transferAuthority(Integer authorizeeUserId, Subscriber<BaseResultBean> subscriber) {
        Map<String, Integer> map = new HashMap<>();
        map.put("authorizeeUserId", authorizeeUserId);
        RetrofitClient.getInstance().getApiService().transferAuthority(UrlContants.TRANSFER_AUTHORITY, map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 解除绑定（自身或其他用户）
     *
     * @param unbundlingUserId 被授权用户标识
     * @param subscriber
     */
    @Override
    public void unbindWatch(Integer unbundlingUserId, Subscriber<BaseResultBean> subscriber) {
        Map<String, Integer> map = new HashMap<>();
        map.put("unbundlingUserId", unbundlingUserId);
        RetrofitClient.getInstance().getApiService().unbindWatch(UrlContants.UNBIND_WATCH, map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 恢复出厂设置
     *
     * @param subscriber
     */
    @Override
    public void resumeFactory(Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().resumeFactory(UrlContants.RESUME_FACTORY)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 编辑主页功能区
     *
     * @param subscriber
     */
    @Override
    public void editHomePagerFunction(String functionSigns, Subscriber<BaseResultBean> subscriber) {
        Map<String, String> map = new HashMap<>();
        map.put("functionSigns", functionSigns);
        RetrofitClient.getInstance().getApiService().editHomePagerFunction(UrlContants.EDIT_HOME_PAGER_FUNCTION, map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 获取所有功能
     *
     * @param subscriber
     */
    @Override
    public void getAllFunction(Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().getAllFunction(UrlContants.GET_ALL_FUNCATION)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 获取未应用的功能
     *
     * @param subscriber
     */
    @Override
    public void getNotUseFunction(Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().getNotUseFunction(UrlContants.GET_NOT_USE_FUNCATION)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 获取通讯录
     * @param subscriber
     */
    @Override
    public void listAddressBook(Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().listAddressBook(UrlContants.LIST_ADDRESS_BOOK)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 上传文件
     *
     * @param file       文件
     * @param subscriber
     */
    @Override
    public void uploadImg(File file, Subscriber<BaseResultBean<String>> subscriber) {
        //MediaType.parse("image/jpg") 告诉服务器上传文件类型,对应请求体中的Content-Type:image/jpg
        RequestBody requestFile = RequestBody.create(MediaType.parse("image/jpg"), file);
        MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), requestFile);
        RetrofitClient.getInstance().getApiService().uploadImg(UrlContants.UPLOAD_IMG, body)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 上传通讯录
     * @param addressBook
     * @param subscriber
     */
    @Override
    public void uploadAddressBook(String addressBook, Subscriber<BaseResultBean> subscriber) {
        RequestBody requestJson= RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),addressBook);
        RetrofitClient.getInstance().getApiService().uploadAddressBook(UrlContants.UPLOAD_ADDRESS_BOOK,requestJson)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 上传贴心设置
     * @param isReservePower
     * @param isPowerSaving
     * @param isCallPosition
     * @param isAutoAnswer
     * @param isShieldStrangeCall
     * @param isAutoBoot
     * @param isAutoShutdown
     * @param isNoShutdown
     * @param isEnableVolte
     * @param bootTime
     * @param shutdownTime
     * @param subscriber
     */
    @Override
    public void updateIntimateSet(Boolean isReservePower, Boolean isPowerSaving, Boolean isCallPosition, Boolean isAutoAnswer,
                                  Boolean isShieldStrangeCall, Boolean isAutoBoot, Boolean isAutoShutdown, Boolean isNoShutdown,
                                  Boolean isEnableVolte, String bootTime, String shutdownTime,Subscriber<BaseResultBean> subscriber) {
        Map<String,Object> map = new HashMap<>();
        if (isReservePower != null){
            map.put("isReservePower",isReservePower);
        }
        if (isPowerSaving != null){
            map.put("isPowerSaving",isPowerSaving);
        }
        if (isCallPosition != null){
            map.put("isCallPosition",isCallPosition);
        }
        if (isAutoAnswer != null){
            map.put("isAutoAnswer",isAutoAnswer);
        }
        if (isShieldStrangeCall != null){
            map.put("isShieldStrangeCall",isShieldStrangeCall);
        }
        if (isAutoBoot != null){
            map.put("isAutoBoot",isAutoBoot);
        }
        if (isAutoShutdown != null){
            map.put("isAutoShutdown",isAutoShutdown);
        }
        if (isNoShutdown != null){
            map.put("isNoShutdown",isNoShutdown);
        }
        if (isEnableVolte != null){
            map.put("isEnableVolte",isEnableVolte);
        }
        if (bootTime != null){
            map.put("bootTime",bootTime);
        }
        if (shutdownTime != null){
            map.put("shutdownTime",shutdownTime);
        }
        RetrofitClient.getInstance().getApiService().updateIntimateSet(UrlContants.UPDATE_INTIMATE_SET,map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 获取贴心设置
     * @param subscriber
     */
    @Override
    public void getIntimateSet(Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().getIntimateSet(UrlContants.GET_INTIMATE_SET)
        .compose(RetrofitClient.getInstance().schedulersTransformer())
        .subscribe(subscriber);
    }

    /**
     * 远程关机
     * @param subscriber
     */
    @Override
    public void remoteShutdown(Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().remoteShutdown(UrlContants.REMOTE_SHUT_DOWN)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 获取课程表
     * @param subscriber
     */
    @Override
    public void getCourse(Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().getCourse(UrlContants.GET_COURSE)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 上传课程表
     * @param course
     * @param subscriber
     */
    @Override
    public void uploadCourse(String course, Subscriber<BaseResultBean> subscriber) {
        RequestBody requestJson= RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),course);
        RetrofitClient.getInstance().getApiService().uploadCourse(UrlContants.UPLOAD_COURSE,requestJson)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 获取位置
     * @param subscriber
     */
    @Override
    public void getLocation(Subscriber<BaseResultBean<LocationBean>> subscriber) {
        RetrofitClient.getInstance().getApiService().getLocation(UrlContants.GET_LOCATION)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 获取最后位置
     * @param subscriber
     */
    @Override
    public void getLastLocation(Subscriber<BaseResultBean<LocationBean>> subscriber) {
        RetrofitClient.getInstance().getApiService().getLastLocation(UrlContants.GET_LAST_LOCATION)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 获取安全围栏列表
     * @param pageNum
     * @param pageSize
     * @param subscriber
     */
    @Override
    public void getSecurityFence(Integer pageNum, Integer pageSize, Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().getSecurityFence(UrlContants.GET_SECURITY_FENCE,pageNum,pageSize)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 添加围栏
     * @param name
     * @param remindWay
     * @param fenceRange
     * @param remindTime
     * @param remindDays
     * @param fenceLat
     * @param fenceLng
     * @param subscriber
     */
    @Override
    public void addSecurityFence(String name, Integer remindWay, Integer fenceRange, String remindTime, String remindDays, String fenceLat, String fenceLng, Subscriber<BaseResultBean> subscriber) {
        Map<String,Object> map = new HashMap<>();
        map.put("name",name);
        map.put("remindWay",remindWay);
        map.put("fenceRange",fenceRange);
        if (remindTime != null) {
            map.put("remindTime", remindTime);
        }
        if (remindDays != null) {
            map.put("remindDays", remindDays);
        }
        map.put("fenceLat",fenceLat);
        map.put("fenceLng",fenceLng);
        RetrofitClient.getInstance().getApiService().addSecurityFence(UrlContants.ADD_SECURITY_FENCE,map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 更新安全围栏
     * @param id
     * @param name
     * @param remindWay
     * @param fenceRange
     * @param remindTime
     * @param remindDays
     * @param fenceLat
     * @param fenceLng
     * @param subscriber
     */
    @Override
    public void updateSecurityFence(Integer id, String name, Integer remindWay, Integer fenceRange, String remindTime, String remindDays, String fenceLat, String fenceLng, Subscriber<BaseResultBean> subscriber) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("name",name);
        map.put("remindWay",remindWay);
        map.put("fenceRange",fenceRange);
        if (remindTime != null) {
            map.put("remindTime", remindTime);
        }
        if (remindDays !=null) {
            map.put("remindDays", remindDays);
        }
        map.put("fenceLat",fenceLat);
        map.put("fenceLng",fenceLng);
        RetrofitClient.getInstance().getApiService().updateSecurityFence(UrlContants.UPDATE_SECURITY_FENCE,map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 启用/关闭安全围栏
     * @param id
     * @param isEnable
     * @param subscriber
     */
    @Override
    public void isEnableSecurityFence(Integer id, Boolean isEnable, Subscriber<BaseResultBean> subscriber) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("isEnable",isEnable);
        RetrofitClient.getInstance().getApiService().isEnableSecurityFence(UrlContants.ISENABLE_SECURITY_FENCE,map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 删除安全围栏
     * @param id
     * @param subscriber
     */
    @Override
    public void deleteSecurityFence(Integer id, Subscriber<BaseResultBean> subscriber) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        RetrofitClient.getInstance().getApiService().deleteSecurityFence(UrlContants.DELETE_SECURITY_FENCE,map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 获取轨迹信息
     * @param date
     * @param subscriber
     */
    @Override
    public void getTrack(String date, Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().getTrack(UrlContants.GET_TRACK,date)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 获取运动统计
     * @param subscriber
     */
    @Override
    public void getSportsCount(Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().getSportsCount(UrlContants.GET_SPORTS_COUNT)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 获取最后运动统计
     * @param subscriber
     */
    @Override
    public void getLastSportsCount(Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().getLastSportsCount(UrlContants.GET_LAST_SPORT_COUNT)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void listGroup(Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().listGroup(UrlContants.LIST_GROUP)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void listManageWatch(Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().listManageWatch(UrlContants.LIST_MANAGE_WATCH)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void listGroupAllowUser(Integer watchId, Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().listGroupAllowUser(UrlContants.LIST_GROUP_ALLOW_USER,watchId)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void uploadGroupHead(File file, Subscriber<BaseResultBean> subscriber) {
        RequestBody requestFile = RequestBody.create(MediaType.parse("image/jpg"), file);
        MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), requestFile);
        RetrofitClient.getInstance().getApiService().uploadGroupHead(UrlContants.UPLOAD_GROUP_HEAD, body)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void createGroup(String json, Subscriber<BaseResultBean> subscriber) {
        RequestBody requestJson= RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),json);
        RetrofitClient.getInstance().getApiService().createGroup(UrlContants.CREATE_GROUP,requestJson)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void deleteGroup(Integer groupId, Subscriber<BaseResultBean> subscriber) {
        Map<String,Object> map = new HashMap<>();
        map.put("groupId",groupId);
        RetrofitClient.getInstance().getApiService().deleteGroup(UrlContants.DELETE_GROUP,map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void updateGroupName(Integer groupId, String name, Subscriber<BaseResultBean> subscriber) {
        Map<String,Object> map = new HashMap<>();
        map.put("groupId",groupId);
        map.put("name",name);
        RetrofitClient.getInstance().getApiService().updateGroupName(UrlContants.UPDATE_GROUP_NAME,map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void listGroupMember(Integer groupId, Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().listGroupMember(UrlContants.LIST_GROUP_MEMBER,groupId)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void addGroupMember(String json, Subscriber<BaseResultBean> subscriber) {
        RequestBody requestJson= RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),json);
        RetrofitClient.getInstance().getApiService().addGroupMember(UrlContants.ADD_GROUP_MEMBER,requestJson)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void deleteGroupMember(String json, Subscriber<BaseResultBean> subscriber) {
        RequestBody requestJson= RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),json);
        RetrofitClient.getInstance().getApiService().deleteGroupMember(UrlContants.DELETE_GROUP_MEMBER,requestJson)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void quitGroup(Integer groupId, Subscriber<BaseResultBean> subscriber) {
        Map<String,Object> map = new HashMap<>();
        map.put("groupId",groupId);
        RetrofitClient.getInstance().getApiService().quitGroup(UrlContants.QUIT_GROUP,map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void sendGroupMsg(String json, Subscriber<BaseResultBean> subscriber) {
        RequestBody requestJson= RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),json);
        RetrofitClient.getInstance().getApiService().sendGroupMsg(UrlContants.SEND_GROUP_MSG,requestJson)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    /**
     * 上传群语音
     * @param groupId
     * @param file
     * @param subscriber
     */
    @Override
    public void uploadGroupVoice(Integer groupId, File file, Subscriber<BaseResultBean> subscriber) {
        RequestBody requestFile = RequestBody.create(MediaType.parse("audio/*"),file);
        RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM)
                .addFormDataPart("groupId",groupId+"")
                .addFormDataPart("file", file.getName(), requestFile)
                .build();

        RetrofitClient.getInstance().getApiService().uploadGroupVoice(UrlContants.UPLOAD_GROUP_VOICE, requestBody)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void getGroupMsg(Integer groupId, Integer msgId, Integer pageSize, Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().getGroupMsg(UrlContants.GET_GROUP_MSG,groupId,msgId,pageSize)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void listGroupMsg(Integer groupId, Integer msgId, Integer pageNum, Integer pageSize, Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().listGroupMsg(UrlContants.LIST_GROUP_MSG,groupId,msgId,pageNum,pageSize)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void remotePhoto(Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().remotePhoto(UrlContants.REMOTE_PHOTO)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void listPhoto(Integer pageNum, Integer pageSize, Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().listPhoto(UrlContants.LIST_PHOTO,pageNum,pageSize)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void deletePhoto(String ids, Subscriber<BaseResultBean> subscriber) {
        Map<String,Object> map = new HashMap<>();
        map.put("ids",ids);
        RetrofitClient.getInstance().getApiService().deletePhoto(UrlContants.DELETE_PHOTO,map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void oneWayListening(Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().oneWayListening(UrlContants.ONE_WAY_LISTING)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void listSchedule(Integer pageNum, Integer pageSize, Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().listSchedule(UrlContants.LIST_SCHEDULE,pageNum,pageSize)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void addSchedule(String remindTime, Integer remindType, String remindDays, String remindContent, Subscriber<BaseResultBean> subscriber) {
        Map<String,Object> map = new HashMap<>();
        map.put("remindTime",remindTime);
        map.put("remindType",remindType);
        map.put("remindDays",remindDays);
        map.put("remindContent",remindContent);
        RetrofitClient.getInstance().getApiService().addSchedule(UrlContants.ADD_SCHEDULE,map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void updateSchedule(Integer id, String remindTime, Integer remindType, String remindDays, String remindContent, Subscriber<BaseResultBean> subscriber) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("remindTime",remindTime);
        map.put("remindType",remindType);
        map.put("remindDays",remindDays);
        map.put("remindContent",remindContent);
        RetrofitClient.getInstance().getApiService().updateSchedule(UrlContants.UPDATE_SCHEDULE,map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void isEnableSchedule(Integer id, Boolean isEnable, Subscriber<BaseResultBean> subscriber) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("isEnable",isEnable);
        RetrofitClient.getInstance().getApiService().isEnableSchedule(UrlContants.IS_ENABLE_SCHEDULE,map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void deleteSchedule(Integer id, Subscriber<BaseResultBean> subscriber) {
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        RetrofitClient.getInstance().getApiService().deleteSchedule(UrlContants.DELETE_SCHEDULE,map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }


    @Override
    public void getMessage(Integer pageNum, Integer pageSize, Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().getMessage(UrlContants.GET_MESSAGE,pageNum,pageSize)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void agreeBindWatch(Integer msgId, Subscriber<BaseResultBean> subscriber) {
        Map<String,Object> map = new HashMap<>();
        map.put("msgId",msgId);
        RetrofitClient.getInstance().getApiService().agreeBindWatch(UrlContants.AGREE_BIND_WATCH,map)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void listOneWayListeningUser(Subscriber<BaseResultBean> subscriber) {
        RetrofitClient.getInstance().getApiService().listOneWayListeningUser(UrlContants.LISTENER_USER)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void getMessageGroup(Subscriber<BaseResultBean<NotificationCategoryBean[]>> subscriber) {
        RetrofitClient.getInstance().getApiService().getMessageGroup(UrlContants.GET_MESSAGE_GROUP)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }

    @Override
    public void listMessage(Integer pageNum,Integer pageSize,Integer msgId,Integer groupId,Subscriber<BaseResultBean<NotificationDetailBean[]>> subscriber) {
        RetrofitClient.getInstance().getApiService().listMessage(UrlContants.LIST_MESSAGE,pageNum,pageSize,msgId,groupId)
                .compose(RetrofitClient.getInstance().schedulersTransformer())
                .subscribe(subscriber);
    }
}
